import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Stack;

class Solution1047 {
     public String removeDuplicates(String s) {
        if(s.length() == 1 ) return s ;
        int len = s.length() ;
        char[] arr = s.toCharArray() ;
        Deque<Character> deque = new ArrayDeque<>() ;
        for(int i=0 ; i < len ; i ++){
            if(!deque.isEmpty() && deque.peekLast().equals(arr[i])){
                deque.pollLast() ;
            }else{
                deque.add(arr[i]);
            }
        }
        StringBuilder strbu = new StringBuilder() ;
        while(!deque.isEmpty()){
               strbu.append(deque.pop());
        }
        return strbu.toString() ;

    }
}